Applied Generative AI for AI Developers
| Feature | Vector DB RAG | Graph RAG |
|---|---|---|
| Storage | Dense embeddings (vectors) | Nodes & relationships |
| Retrieval | Nearest neighbor search | Graph traversal queries |
| Scalability | Efficient for large text | More complex, depends on structure |
| Context | Semantic similarity only | Rich, structured context |
| Use Case | Unstructured knowledge | Structured reasoning |
Niels Bohr.Bohr
MATCH (p:Person {id: "Bohr"})-[:COLLABORATED_WITH]->(collaborator) RETURN collaborator.idMATCH (p:Person {id: "Bohr"})-[:STUDY_UNDER*2]->(mentor) RETURN mentor.idThe vector search for this would have to include potentially several chunks of text and may still not get all the collaborators whereas the graph retrieval would be deterministic and more accurate.
retriever = vectorstore.as_retriever()
retriever.get_relevant_documents("Who all did Bohr collaborate with?")SELECT AVG(trip_distance) AS avg_trip_distance
FROM nyc_taxi_data
WHERE DATE(tpep_pickup_datetime) = '2024-12-11';from langchain.sql_database import SQLDatabase
from langchain.chains import SQLDatabaseChain
from langchain_aws import ChatBedrockConverse
import boto3
# Initialize Bedrock client
bedrock = boto3.client(
service_name='bedrock-runtime',
region_name='us-east-1' # replace with your region
)
# Initialize the LLM
llm = ChatBedrockConverse(
model_id="anthropic.claude-3-sonnet-20240229", # or your preferred Claude model
client=bedrock,
model_kwargs={"temperature": 0}
)
# Connect to database
db = SQLDatabase.from_uri("sqlite:///example.db")
# Create the chain
sql_chain = SQLDatabaseChain.from_llm(llm=llm, database=db, verbose=True)
# Run the query
sql_chain.run("What are the top 5 research topics?")| Metric | Description |
|---|---|
| Cross-Modal Relevance | Alignment between retrieved items across modalities |
| Response Coherence | Integration of multi-modal information in outputs |
| Retrieval Latency | Time to fetch and process multi-modal context |
| Memory Usage | Resource requirements for different modalities |